import { ref } from "vue"
import store from "@/store"
import { defineStore } from "pinia"
// import { getDepartment } from "@/api/team"

export const useDepartmentStore = defineStore(
  "department",
  () => {
    const departmentListStore = ref<string[]>([])

    /** 设置部门列表 */
    const setDepartmentList = (value: string[]) => {
      departmentListStore.value = value
    }
    // const getDepartmentFn = async () => {
    //   await getDepartment({
    //     page: 1,
    //     size: 100
    //   }).then((res: any) => {
    //     setDepartmentList(res.data.list)
    //   })
    // }
    /**actions */
    // {
    //   //部门持久化
    //   getDepartment({
    //     page: 1,
    //     size: 100
    //   }).then((res: any) => {
    //     setDepartmentList(res.data.list)
    //   })
    // }
    /**actions END */
    return {
      departmentListStore,
      setDepartmentList
      // getDepartmentFn
    }
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          storage: localStorage
          // paths: ["jobListStore", "authListStore"] //指定要长久化的字段
        }
      ]
    }
  }
)
/** 在 setup 外使用 */
export function useDepartmentStoreHook() {
  return useDepartmentStore(store)
}
